<?php
// +----------------------------------------------------------------------
// | Siteplus [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.brsttech.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Pillar <service@brsttech.com>
// +----------------------------------------------------------------------
namespace app\admin\model;
use think\Model;

class Group extends Model{

    protected $pk       = 'id';
    protected $table    = 'sp_system_group';
    protected $autoWriteTimestamp = true;
    protected $pageNumber = 20;

    /**
     * 列表
     * @access public
     * @param array $where
     */
    public function select_lists(){
        return $this->order('id desc')->paginate($this->pageNumber);
    }
    
    /**
     * 管理员编辑列表群组选择
     * @access public
     * @param array $where
     */
    public function select_lists_user(){
        return $this->order('id desc')->paginate($this->pageNumber);
    }

    /**
     * 单个
     * @param int $param
     * @return array
     */
    public function find_info($param) {
        return self::get($param);
    }
    
    /**
     * 添加
     * @param array $param
     * @return int
     */
    public function add_data($param) {
        $auth_ids = json_encode(explode(',',$param['auth_ids']));
        $data = [
            'title'       => $param['title'],
            'auth_ids'    => $auth_ids,
            'about'       => $param['about'],
            'create_time' => time(),
            'update_time' => time(),
        ];
        return $this->insertGetId($data);
    }
    
    /**
     * 编辑
     * @param type $param
     */
    public function edit_data($param) {
        $auth_ids = json_encode(explode(',',$param['auth_ids']));
        $data = [
            'title'       => $param['title'],
            'auth_ids'    => $auth_ids,
            'about'       => $param['about'],
            'update_time' => time(),
        ];
        $where = ['id'=>$param['id']];
        return $this->where($where)->update($data);
    }
    
    /**
     * 删除数据
     * @param int $id
     */
    public function delete_data($id) {
        return $this->destroy($id);
    }
}